﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ObjectBakery.Tests.TestDoubles;
using ObjectBakery.Helpers;

namespace ObjectBakery.Tests.TestFactories
{
    public class TestTableFactory
    {
        public DataTable BuildProducts()
        {
             
             //build up Products Table
             DataTable table = new DataTable("Products");
             table.Columns.Add("ID", typeof(int));
             table.Columns.Add("SKU", typeof(string));
             table.Columns.Add("Name", typeof(string));
             table.Columns.Add("Description", typeof(string));
             table.Columns.Add("Assets", typeof(List<Asset>));


             DataRow dataRow1 = table.NewRow();
             dataRow1["ID"] = table.Rows.Count + 1;
             dataRow1["SKU"] = Guid.NewGuid().ToString();
             dataRow1["Name"] = "Banana Gun";
             dataRow1["Description"] = "Product stored in a table";
             dataRow1["Assets"] = new TestAssetFactory().Build();

             table.Rows.Add(dataRow1);

             DataRow dataRow2 = table.NewRow();
             dataRow2["ID"] = table.Rows.Count + 1;
             dataRow2["SKU"] = Guid.NewGuid().ToString();
             dataRow2["Name"] = "Banana Gun";
             dataRow2["Description"] = "Product stored in a table";
             dataRow2["Assets"] = new TestAssetFactory().Build();

             table.Rows.Add(dataRow2);

             DataRow dataRow3 = table.NewRow();
             dataRow3["ID"] = table.Rows.Count + 1;
             dataRow3["SKU"] = Guid.NewGuid().ToString();
             dataRow3["Name"] = "Banana Gun";
             dataRow3["Description"] = "Product stored in a table";
             dataRow3["Assets"] = new TestAssetFactory().Build();

             table.Rows.Add(dataRow3);

             return table;
       
        }

        public DataTable BuildAssets()
        {

            //build up Products Table
            DataTable table = new DataTable("Assets");
            table.Columns.Add("ID", typeof(int));
            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Format", typeof(AssetFormat));
            table.Columns.Add("Data", typeof(byte[]));


            DataRow dataRow1 = table.NewRow();
            dataRow1["ID"] = table.Rows.Count + 1;
            dataRow1["Name"] = "Image1";
            dataRow1["Format"] = AssetFormat.Jpg;
            dataRow1["Data"] = AssemblyHelper.GetResourceAsMemoryStream(this.GetType().Assembly,
                            "TestAssets.1220080919.jpg").ToArray();

            table.Rows.Add(dataRow1);

            DataRow dataRow2 = table.NewRow();
            dataRow2["ID"] = table.Rows.Count + 1;
            dataRow2["Name"] = "Brochure";
            dataRow2["Format"] = AssetFormat.Docx;
            dataRow2["Data"] = AssemblyHelper.GetResourceAsMemoryStream(this.GetType().Assembly,
                               "TestAssets.23424297987a.docx").ToArray();

            table.Rows.Add(dataRow2);

            DataRow dataRow3 = table.NewRow();
            dataRow3["ID"] = table.Rows.Count + 1;
            dataRow3["Name"] = "Image2";
            dataRow3["Format"] = AssetFormat.Jpg;
            dataRow3["Data"] = AssemblyHelper.GetResourceAsMemoryStream(this.GetType().Assembly,
                                "TestAssets.1220080919a.jpg").ToArray();

            table.Rows.Add(dataRow3);

            return table;

        }
    }
}
